package ar.gov.hackaton.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import ar.gov.hackaton.dao.CensoHogarDao;
import ar.gov.hackaton.dao.ProvinciaInfo;
import ar.gov.hackaton.model.CategoriaCenso;
import ar.gov.hackaton.service.CensoHogarService;

@Controller
@RequestMapping("/censo/")
public class CensoHogarController {

	private static final Logger logger = LoggerFactory.getLogger(CensoHogarController.class);

	@Autowired
	private CensoHogarDao censoHogarDao;

	@Autowired
	private CensoHogarService censoHogarService;

	@RequestMapping(value = "listProvinciasInfo", method = RequestMethod.GET)
	public @ResponseBody
	List<ProvinciaInfo> listProvinciasInfo(@RequestParam(value = "categoryName", required = false) String categoryName,
			HttpServletRequest request, HttpServletResponse response) {
		response.addHeader("Access-Control-Allow-Origin", "*");
		return censoHogarService.listProvinciasInfo(categoryName);
	}

	@RequestMapping(value = "listCategoryNames", method = RequestMethod.GET)
	public @ResponseBody
	List<String> listCategoryNames(HttpServletRequest request, HttpServletResponse response) {
		response.addHeader("Access-Control-Allow-Origin", "*");
		return censoHogarService.listCategoryNames();
	}
	
	@RequestMapping(value = "listCategoriaCenso", method = RequestMethod.GET)
	public @ResponseBody
	List<CategoriaCenso> listCategoriaCenso(HttpServletRequest request, HttpServletResponse response) {
		response.addHeader("Access-Control-Allow-Origin", "*");
		return censoHogarService.listCategoriaCenso();
	}

	@RequestMapping(value = "getProvincias", method = RequestMethod.GET)
	public @ResponseBody
	String getShopInJSON() {
		return "[{id=1 nombre=papap}, {id=2 nombre=pepepepe}]";

	}
}
